package com.enhe.gck.controller;

import com.enhe.gck.communal.ClientInvokingParam;
import com.enhe.gck.communal.Resp;
import com.enhe.gck.controller.vo.CaptureImageVO;
import com.enhe.gck.controller.vo.ClientInvokingRespVO;
import com.enhe.gck.controller.vo.WeightPrintInfoVO;
import com.enhe.gck.pojo.Goods;
import com.enhe.gck.pojo.OrderCommon;
import com.enhe.gck.service.impl.GckFrontService;
import com.enhe.gck.service.impl.GoodsService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 前置机调用controller
 */
@RestController
@RequestMapping("front")
@AllArgsConstructor
public class GckFrontController {

    private GckFrontService gckFrontService;
    private GoodsService goodsService;


    /**
     * 根据提货码获取订单信息
     */
    @GetMapping("getOrderInfoByPickupCode/{pickupCode}")
    public Resp<OrderCommon> getOrderInfoByPickupCode(@PathVariable String pickupCode, Boolean onlyRead) {
        return gckFrontService.getOrderInfoByPickupCode(pickupCode, onlyRead);
    }

    /**
     * 根据车号及日期获取打印单列表信息
     */
    @GetMapping("getOrderInfoList/{carNo}/{orderType}")
    public Resp<List<OrderCommon>> getOrderInfoList(@PathVariable String carNo, @PathVariable String orderType) {
        return gckFrontService.getOrderInfoList(carNo, orderType);
    }

    /**
     * 根据车号获取可补打的【原材料验收单】信息列表
     */
    @GetMapping("getReceivingReportOrderList/{carNo}")
    public Resp<List<OrderCommon>> getReceivingReportOrderList(@PathVariable String carNo) {
        return gckFrontService.getReceivingReportOrderList(carNo);
    }

    /**
     * 根据车牌号获取可补打提货单的订单列表信息
     */
    @GetMapping("getBillOfLadingOrderList/{carNo}/{orderType}")
    public Resp<List<OrderCommon>> getBillOfLadingOrderList(@PathVariable String carNo, @PathVariable String orderType) {
        return gckFrontService.getBillOfLoadingOrderList(carNo, orderType);
    }

    /**
     * 将ic卡号绑定订单
     *
     * @param orderId     订单主键id
     * @param icCardNo    ic卡号
     * @param orderTypeEn 订单类型(en)
     * @return resp
     */
    @GetMapping("bindCard/{orderId}")
    public Resp<WeightPrintInfoVO> bindCard(@PathVariable Long orderId, String icCardNo, String orderTypeEn) {
        return gckFrontService.bindCard(orderId, icCardNo, orderTypeEn);
    }

    @GetMapping("billOfLoadingOrderPatchwork/{orderId}")
    public Resp<WeightPrintInfoVO> billOfLoadingOrderPatchwork(@PathVariable Long orderId) {
        return gckFrontService.billOfLoadingOrderPatchwork(orderId);
    }

    /**
     * 根据订单id执行前置机执行的命令(上磅,称重,装车)
     *
     * @param param 前置机监听参数
     * @return resp
     */
    @PostMapping("executeCommand")
    public Resp<ClientInvokingRespVO> executeCommand(@RequestBody ClientInvokingParam param) {
        return gckFrontService.executeCommand(param);
    }

    /**
     * 前置机称重图片上传接收
     *
     * @param captureImageVO 前置机抓拍的图片
     * @return resp
     */
    @PostMapping("uploadWeightPic")
    public Resp<String> uploadWeightPic(CaptureImageVO captureImageVO) {
        return gckFrontService.uploadWeightPic(captureImageVO);
    }

    /**
     * 根据IC卡号获取打印单信息
     */
    @GetMapping("getPrintInfoByIcCardNo")
    public Resp<WeightPrintInfoVO> getPrintInfoByIcCardNo(@RequestParam(required = false) String icCardNo,
                                                          @RequestParam(required = false) Boolean patchworkFlag,
                                                          @RequestParam(required = false) String patchworkOrderNo) {
        return gckFrontService.getPrintInfoByIcCardNo(icCardNo, patchworkFlag, patchworkOrderNo);
    }

    /**
     * 同步获取所有产品列表信息
     */
    @GetMapping("getAllGoodsList")
    public Resp<List<Goods>> getAllProductList() {
        return goodsService.getAllProductList();
    }

    /**
     * 根据订单号获取订单信息
     */
    @PostMapping("/getOrderInfoByOrderNo")
    public Resp<List<OrderCommon>> getOrderInfoByOrderNo(@RequestBody List<String> orderNo) {
        return gckFrontService.getOrderInfoByOrderNo(orderNo);
    }

    /**
     * 根据订单号修改补包数
     *
     * @param carNo          车牌号
     * @param supplementBags 补包数
     * @return
     */
    @GetMapping("/updateOrderSupplementBags")
    public Resp<String> updateOrderSupplementBags(String carNo, Integer supplementBags) {
        return gckFrontService.updateOrderSupplementBags(carNo, supplementBags);
    }
}
